#pragma once

#include "OCGIS/GISReader.h"
#include "OCMain/Image.h"
#include "OCMain/Log.h"
#include "OCMain/FileUtil.h"
#include "OCMain/ZipUtil.h"
#include "json/json.h"

using namespace OCPP;

void imageSave()
{
    ColourValue color(0.0, 1.0, 1.0, 1.0);
    Image image(PF_BYTE_RGBA, 720, 480, 1);
    for (int i = 0; i < 240; i++)
    {
        for (int j = 0; j < 720; j++)
        {
            image.setColourAt(color, j, i, 0);
        }
    }
    //image.save("I:/test/freeimage.webp");
    //GISReader reader1;
    //reader1.open("");
}

//String path = "\\\\10.104.207.155\\Cesium\\Assets\\2025\\EC";
String path = "G:\\ECMWF_HR\\VGRD_10M";
String file_ext = "";

void gzFolder()
{
    int count = 0;
    StringVector files = FileUtil::findFiles(path);
    for (auto file : files)
    {
        String ext = FileUtil::getFileExtension(file);
        if (ext.size() == 3)
        {
            String rawFileName = joinPath(path, file);
            String gzFileName = rawFileName + ".gz";
            if (!FileUtil::existFile(gzFileName))
            {
                String buffer = FileUtil::getFileBinary(rawFileName);
                String gzBuffer = ZipUtil::gzipCompress(buffer);
                FileUtil::writeFile(gzFileName, gzBuffer);
                count++;
            }
        }
    }
    OCPP_LOG_INFO << "GZ File Count:" << count << "\n";
}

void jsonFolder()
{
    Json::Value root;

    int count = 0;
    StringVector files = FileUtil::findFiles(path);
    for (auto file : files)
    {
        if (file == "." || file == "..") continue;
        String ext = FileUtil::getFileExtension(file);
        if (ext == file_ext)
        {
            if (file_ext == "gz") file = file.substr(0, file.find_last_of('.'));
            root.append(file);
        }
    }

    if (root.size() > 0)
    {
        String name, path1;
        StringUtil::splitFilename(path, name, path1);

        String jsonFileName = joinPath(path1, name + ".json");
        String jsonString = root.toStyledString();
        FileUtil::writeFile(jsonFileName, jsonString);
    }

    OCPP_LOG_INFO << "File Count:" << root.size() << "\n";
}
